package com.mos.common;

import com.mos.base.Globl;
import org.apache.log4j.Logger;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Package Name: com.mos.common
 * User: grq
 * Date: 2016/4/6
 * Time: 11:20
 * Description:some des here!
 */
public class LoginInterceptor implements HandlerInterceptor {


    private static Logger log = Logger.getLogger(LoginInterceptor.class);

    private final static String LOGIN_URI_PREFIX = "/login";
    private final static String LOGIN_PAGE_URI = LOGIN_URI_PREFIX + "/input";

    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response, Object handler) throws Exception {

        HttpSession session = request.getSession();
        Object user = session.getAttribute(Globl.SESSION_USER_KEY);

        String userReqUri = request.getRequestURI();

       /* if (null == user && userReqUri.indexOf("CaptchaImage/create.action") == -1) {
            response.sendRedirect(request.getContextPath() + LOGIN_PAGE_URI);
            return false;//不再走剩余的拦截器
        }*/

        return true;

    }

    public void postHandle(HttpServletRequest request,
                           HttpServletResponse response, Object handler,
                           ModelAndView modelAndView) throws Exception {

    }

    public void afterCompletion(HttpServletRequest request,
                                HttpServletResponse response, Object handler, Exception ex)
            throws Exception {

    }


}
